home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / workbench / fullbench-3.00 / src / fullbench.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  5KB  |  200 lines

  1. /*
  2. **
  3. */
  4. #define REVISION "3.0"
  5. #define REVDATE  "30.1.2000"
  6. #define AUTHOR   "Gunther Nikl"
  7. #define PROGNAME "FullBench"
  8. #define PORTNAME "FullBench.rendezvous"
  9.  
  10. /*
  11. **
  12. */
  13. #include <string.h>
  14. #include <dos/dosextens.h>
  15. #include <intuition/imageclass.h>
  16. #include <intuition/gadgetclass.h>
  17. #include <libraries/screennotify.h>
  18. #include <proto/screennotify.h>
  19. #include <proto/intuition.h>
  20. #include <proto/exec.h>
  21. #include <proto/dos.h>
  22. #include "compiler.h"
  23.  
  24. /*
  25. **
  26. */
  27. struct FullBenchArgs {
  28.   APTR             IntBase;
  29.   struct Image    *id;
  30.   struct DrawInfo *dri;
  31.   struct Gadget   *gad;
  32.   struct Window   *win;
  33. };
  34.  
  35. ULONG REGARGS Full(struct FullBenchArgs *fb,LONG on);
  36.  
  37. /*
  38. **
  39. */
  40. #if defined(__GNUC__)
  41.  
  42. __asm("jra _FullBench");
  43.  
  44. STATIC APTR new_object(REG(a6,APTR IntuitionBase),REG(a0,APTR classPtr),REG(a1,char *classID),Tag tag,...)
  45. {
  46.   return NewObjectA(classPtr,classID,(struct TagItem *)&tag);
  47. }
  48. #undef NewObject
  49. #define NewObject(a,b,c...) new_object(IntuitionBase,a,b,c)
  50.  
  51. STATIC struct Window *open_window_tags(REG(a6,APTR IntuitionBase),REG(a0,struct NewWindow *newWindow),Tag tag,...)
  52. {
  53.   return OpenWindowTagList(newWindow,(struct TagItem *)&tag);
  54. }
  55. #undef OpenWindowTags
  56. #define OpenWindowTags(a,b...) open_window_tags(IntuitionBase,a,b)
  57.  
  58. #endif
  59.  
  60. /*
  61. **
  62. */
  63. LONG FullBench(VOID)
  64. { APTR SysBase,DOSBase,ScreenNotifyBase;
  65.   struct ScreenNotifyMessage *snm;
  66.   struct FullBenchArgs fb;
  67.   struct MsgPort *mp,*tport;
  68.   struct Process *pr;
  69.   APTR wbmsg,handle;
  70.  
  71.   SysBase = *(APTR *)4L; pr = (struct Process *)FindTask(NULL);
  72.  
  73.   if (wbmsg=NULL,!pr->pr_CLI)
  74.     wbmsg = (WaitPort(&pr->pr_MsgPort),GetMsg(&pr->pr_MsgPort));
  75.  
  76.   Forbid();
  77.   if ((mp=FindPort(PORTNAME)) != NULL) {
  78.     Signal(mp->mp_SigTask,SIGBREAKF_CTRL_C);
  79.   }
  80.   else if ((tport=CreateMsgPort()) != NULL) {
  81.     tport->mp_Node.ln_Pri  = -1;
  82.     tport->mp_Node.ln_Name = PORTNAME;
  83.     AddPort(tport);
  84.   }
  85.   Permit();
  86.  
  87.   if (!mp && tport) {
  88.     if ((DOSBase=OpenLibrary("dos.library",36L)) != NULL) {
  89.       if ((fb.IntBase=OpenLibrary("intuition.library",0L)) != NULL) {
  90.         if ((ScreenNotifyBase=OpenLibrary("screennotify.library",1L))!= NULL) {
  91.           if ((handle=AddWorkbenchClient(tport,0))) {
  92.             if (Full(&fb,TRUE)) {
  93.               for(;;) {
  94.                 if (Wait(SIGBREAKF_CTRL_C|(1L<<mp->mp_SigBit)) & SIGBREAKF_CTRL_C)
  95.                   break;
  96.                 while ((snm=(struct ScreenNotifyMessage *)GetMsg(tport))) {
  97.                   if (snm->snm_Type == SCREENNOTIFY_TYPE_WORKBENCH)
  98.                     Full(&fb,(LONG)snm->snm_Value);
  99.                   ReplyMsg(&snm->snm_Message);
  100.                 }
  101.               }
  102.               Full(&fb,FALSE);
  103.             }
  104.             while (!RemPubScreenClient(handle)) Delay(10);
  105.           }
  106.           CloseLibrary(ScreenNotifyBase);
  107.         }
  108.         CloseLibrary(fb.IntBase);
  109.       }
  110.       CloseLibrary(DOSBase);
  111.     }
  112.     RemPort(tport); DeleteMsgPort(tport);
  113.   }
  114.  
  115.   if (wbmsg) {
  116.     Forbid();
  117.     ReplyMsg(wbmsg);
  118.   }
  119.  
  120.   return 0;
  121. }
  122.  
  123. /*
  124. **
  125. */
  126. ULONG REGARGS Full(struct FullBenchArgs *fb,LONG on)
  127. { STATIC CONST struct EasyStruct err = {
  128.     5*sizeof(ULONG),
  129.     0,
  130.     PROGNAME" "REVISION "\0$VER: "PROGNAME" "REVISION" ("REVDATE") (c) "AUTHOR,
  131.     "Can't find Worbench screen\nor WB is not backdrop",
  132.     "Continue"
  133.   };
  134.   LREG(a6,APTR IntuitionBase) = fb->IntBase;
  135.   struct Screen *wb_scr;
  136.   struct Window *wb_win;
  137.   ULONG lock,success=FALSE;
  138.  
  139.   if ((wb_scr=LockPubScreen("Amiga Workbench"+6)) == NULL) {
  140.     EasyRequestArgs(NULL, &err, NULL, NULL);
  141.   }
  142.   else {
  143.     lock = LockIBase(0);
  144.     for(wb_win = wb_scr->FirstWindow; wb_win
  145.       && (strncmp(wb_win->ScreenTitle,"Amiga Workbench",15)
  146. #if 0
  147.       && strncmp(wb_win->ScreenTitle,"Attempting to load program",25)
  148.       && strncmp(wb_win->ScreenTitle,"Copyright © 1985-199",20)
  149.       && strncmp(wb_win->ScreenTitle,"Cannot Quit yet",15)
  150. #endif
  151.       || wb_win->Title!=NULL); wb_win = wb_win->NextWindow);
  152.     UnlockIBase(lock);
  153.  
  154.     if (!wb_win) {
  155.       EasyRequestArgs(NULL, &err, NULL, NULL);
  156.     }
  157.     else {
  158.  
  159.       ShowTitle(wb_scr, !on);
  160.       if (on) {
  161.         fb->id = NewObject(NULL, SYSICLASS,
  162.              SYSIA_DrawInfo, fb->dri = GetScreenDrawInfo(wb_scr),
  163.              SYSIA_Which, SDEPTHIMAGE,
  164.              SYSIA_Size, (wb_scr->Flags & SCREENHIRES ? SYSISIZE_MEDRES : SYSISIZE_LOWRES),
  165.              IA_Height,wb_scr->BarHeight+1,
  166.              TAG_DONE);
  167.         fb->gad = NewObject(NULL, BUTTONGCLASS,
  168.              GA_Image, fb->id,
  169.              GA_SysGType, GTYP_SDEPTH,
  170.              TAG_DONE);
  171.         if ((fb->win = OpenWindowTags(NULL, 
  172.             WA_Title,"win_FullBench",
  173.             WA_PubScreen, wb_scr,
  174.             WA_Top, 0,
  175.             WA_Left, 32000,
  176.             WA_Height, fb->id->Height,
  177.             WA_Width, fb->id->Width-1, /* Dunno why I need this -1 */
  178.             WA_AutoAdjust, TRUE,
  179.             WA_Gadgets, fb->gad,
  180.             WA_Flags, WFLG_BORDERLESS,
  181.             TAG_END)))
  182.         {
  183.           ChangeWindowBox(wb_win,wb_win->LeftEdge,0,wb_win->Width,wb_scr->Height);
  184.           success=TRUE;
  185.         }
  186.       } else {
  187.         ChangeWindowBox(wb_win,wb_win->LeftEdge,(wb_scr->BarHeight+1),
  188.           wb_win->Width,wb_scr->Height-(wb_scr->BarHeight+1));
  189.         CloseWindow(fb->win);
  190.         DisposeObject(fb->gad);
  191.         DisposeObject(fb->id);
  192.         FreeScreenDrawInfo(wb_scr,fb->dri);
  193.         success=TRUE;
  194.       }
  195.     }
  196.     UnlockPubScreen(NULL, wb_scr);
  197.   }
  198.   return success;
  199. }
  200.